<?php

include 'config.php';
include 'common.php';


$result = json_decode(urldecode($_GET['data']),true);

$openId  = $openId . "_" . $result['platform'];

//调取注册接口
$post = array();
$post['openid'] = $openId;
$post['type'] = "wechat";
$payload = array(
    'openid' => $openId,
    'city' => $result['city'],
    'country' => $result['country'],
    'province' => $result['province'],
    'sex' => 0 ,
    'headimgurl' => $result['figureurl'],
    'nickname' => $result['nickname'],
    'unionid' => $openId,
);
$post['payload'] = json_encode($payload);
$result = curlRequest($config['LoginApi'],true,$post);

$result = json_decode($result,true);
if($result['code'] == 0) {
    $time = time();
    setcookie("openid",$json->openid,$time + 3600*24*30);
    setcookie("token",$result['data']['token'], $time + 3600*24*30 );
    setcookie("nickname",urlencode($result['data']['nickname']), $time + 3600*24*30 );
    setcookie("avatar",$result['data']['avatar'], $time + 3600*24*30 );
    setcookie("coinbalance",$result['data']['coinbalance'], $time + 3600*24*30 );
    setcookie("uid",$result['data']['uid'], $time + 3600*24*30);
    setcookie("iswenba",1, $time + 3600*24*30);
    header("Location: https://m.mxzhuawawa.com/");

}